using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ECCSystem.BizRule;

namespace ECCSystem.UserControls
{
	public partial class DigUser : Form
	{
		public DigUser()
		{
			InitializeComponent();
		}

		private string m_PersonName = "";
		public string PersonName
		{
			set
			{
				m_PersonName = value;
			}
			get
			{
				return m_PersonName;
			}
		}

		private string m_PersonID = "";
		public string PersonID
		{
			set
			{
				m_PersonID = value;
			}
			get
			{
				return m_PersonID;
			}
		}

		private string m_PersonIP = "";
		public string PersonIP
		{
			set
			{
				m_PersonIP = value;
			}
			get
			{
				return m_PersonIP;
			}
		}

		private void DigUser_Load(object sender, EventArgs e)
		{
			string[] strArr = null; 
			char[] chrArr = "|".ToCharArray();
			ArrayList objAL = new ArrayList();

			ClsUserMaintenance objGetUser = new ClsUserMaintenance();
			DataSet dt = (DataSet)objGetUser.GetList();

			if (dt.Tables.Count == 0)
			{
				return;
			}

			if (m_PersonID != "")
			{
				strArr = m_PersonID.Split(chrArr);
				for (int i = 0; i < strArr.Length; i++)
				{
					if (strArr[i].ToString() != "|" && strArr[i].ToString() != "")
					{
						objAL.Add(strArr[i]);
					}
				}
			}

			dtvUser.AutoGenerateColumns = false;
			dt.Tables[0].Columns.Add("Checked");
			for (int i = 0; i < dt.Tables[0].Rows.Count; i++)
			{
				if ((objAL.Count != 0) && (objAL.Contains(dt.Tables[0].Rows[i]["ID"].ToString())))
				{
					dt.Tables[0].Rows[i]["Checked"] = 0;
				}
				else
				{
					dt.Tables[0].Rows[i]["Checked"] = 1;
				}
				
			}
			dtvUser.DataSource = dt.Tables[0];

			for (int i = 0; i < dtvUser.Rows.Count; i++)
			{
				if ((Convert.ToInt32(dtvUser.Rows[i].Cells["Checked"].Value)) == 0 &&
					(dtvUser.Rows[i].Cells["Checked"].Value != null))
				{
					PersonIP = PersonIP + dtvUser.Rows[i].Cells["IP"].Value.ToString() + "|";
				}
			}
		}

		private void btnYes_Click(object sender, EventArgs e)
		{
			m_PersonName = "";
			m_PersonID = "";
			m_PersonIP = "";

			for (int i = 0; i < dtvUser.Rows.Count; i++)
			{
				if ((Convert.ToInt32(dtvUser.Rows[i].Cells["Checked"].Value)) == 0 &&
					(dtvUser.Rows[i].Cells["Checked"].Value != null))
				{
					PersonID = PersonID + dtvUser.Rows[i].Cells["ID"].Value.ToString() + "|";
					PersonName = PersonName + dtvUser.Rows[i].Cells["UserName"].Value.ToString() + "|";
					PersonIP = PersonIP + dtvUser.Rows[i].Cells["IP"].Value.ToString() + "|";
				}
			}

			this.Close();
		}
	}
}